#coding=utf-8
#构造接口请求目标服务器并获得响应内容
#
import socket
import json

def req(psd):
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client.connect(('212.64.27.86', 7779))
    buffer = []
    dl = len(psd)
    data = '''POST / HTTP/1.1
Accept: */*
Referer: http://212.64.27.86:7779
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)
Host: 212.64.27.86:7779
Content-Length: {0}
Cache-Control: no-cache

{1}'''.format(dl,psd)

    client.send(data.encode('utf-8'))
    # print("数据已发送")
    while True:
        data = client.recv(1024)
        if len(data)==0:
            break
        buffer.append(data.decode('utf-8'))
        # print(data)
    client.close()  # 关闭套接字
    try:
        recvdata = json.loads(''.join(buffer))
    except:
        return ""
    try:
        shD = recvdata['1']  #商行数据
        # print(shD)
    except:
        shD = ''
    try:
        btD = recvdata['2']  #摆摊数据
        # print(btD)
    except:
        btD = ''
    return (shD,btD)


# def main():
#     client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#     client.connect(('212.64.27.86', 7779))
#     req(client)

if __name__ == '__main__':
    a=req('7693E680FC4A30B72B6DAC426BEE0E1C9A8152837DD68CE42ACD1C384DAE6407D7BEB7E7714F81C13716A009EA9F3C9811A6A132340936A725E76105E2EC74E3004FA92852EE044ED0785DA652E5C8168774DD0798815CE6C72174941B111B644DB792BC31C8F91595BBF613AABD3E8A093951EF25BDC60298254B863ED4E395')
    print(a)